Skip to content

Reject Drive API v2 field names instead of dropping them - #425

Draft
shcheklein wants to merge 4 commits into
mainfrom
reject-v2-fields
Draft

shcheklein wants to merge 4 commits into
mainfrom
reject-v2-fields

Conversation

@shcheklein

@shcheklein shcheklein commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

A program written for PyDrive2 1.x names a file with title and places it with a parent object:

file = drive.CreateFile({"title": "Hello.txt", "parents": [{"id": folder_id}]})
file.SetContentString("Hello")
file.Upload()

In 2.0 this upload succeeds and creates a file named "Untitled" in the root of My Drive. Drive API v3 ignores every field it does not know, and the local object still returns file["title"].

What Drive v3 does with v2 metadata

The first two commits are a temporary live test that sent v2 forms to Drive and printed the result (first run, second run).

v2 form Result on Drive
title on create file named "Untitled"
title on update name unchanged
createdDate, modifiedDate, lastViewedByMeDate, labels, indexableText ignored
a made-up field ignored
parents: [{"id": folder}] on create file in the root of My Drive
parents: [{"id": folder}] on update 404 "File not found: {'id': ...}"
properties as a list of {key, value, visibility} stored as properties named key, value and visibility
permission withLink, additionalRoles ignored
permission value 400, emailAddress is required
title in q or orderBy 400 "Invalid Value"

Changes

  • Upload() raises ValueError for a renamed v2 file field and shows the v3 form: title, createdDate, modifiedDate, lastViewedByMeDate, labels, indexableText, thumbnail.
  • Upload() raises TypeError when parents is not a list of ID strings, and for a list or tuple of v2 properties.
  • InsertPermission() raises ValueError for value, withLink, additionalRoles and expirationDate.
  • The checks run before authentication starts and before any request is sent. Upload() looks at every key of the file, not only at pending changes, because a metadata read marks local keys as clean.
  • Nothing is translated: the error shows which v3 form to use.
  • The upgrade guide lists the date fields and describes the errors.

Reads and queries are unchanged. file["title"], and title in q or orderBy, already fail with an error.

Validation

  • Offline tests cover every rejected form on create and on update, after a metadata read, and without credentials. They fail without the change.
  • No README, docs or example snippet uses a v2 form, and none of the rejected names exists in the Drive v3 File or Permission schema.
  • expirationDate was not sent to Drive, because that needs a real user to share with. It is rejected on the strength of the other permission fields being ignored.
  • CI checks on the final commit.

🤖 Generated with Claude Code

shcheklein and others added 3 commits December 1, 2026 07:28
A temporary live test. It uploads, shares and lists with v2 names such as
title and modifiedDate, and fails with a report of what Drive returned. The
fix that follows replaces it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The first run showed that Drive accepts {"parents": [{"id": ...}]} without
an error. This run records where such a file is placed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Drive v3 ignores fields it does not know. A file uploaded with title is
named "Untitled", one uploaded with parent objects lands in the root of
My Drive, and a list of properties is stored under the wrong keys.
Upload() and InsertPermission() now raise for these v2 forms before they
send anything.

This also removes the temporary probe test.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@shcheklein shcheklein left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-scoped change and great live-probe validation. Left a couple of inline comments on parents shape validation and the value permission hint.

Comment thread pydrive2/files.py Resolved
Comment thread pydrive2/files.py Resolved
Comment thread pydrive2/test/test_files_unit.py Resolved

@shcheklein shcheklein left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two validation gaps found; inline details below.

Comment thread pydrive2/files.py Resolved
Comment thread pydrive2/files.py Resolved
Comment thread pydrive2/files.py Resolved
Comment thread pydrive2/files.py Resolved
Comment thread pydrive2/files.py Resolved
Comment thread pydrive2/test/test_files_unit.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Authentication runs before v2 metadata validation in Upload() and InsertPermission(), allowing invalid input to trigger authentication requests or errors instead of the expected migration error.

1 open issue
What changed in this PR

This PR helps PyDrive2 users migrate to Drive API v3 by rejecting known v2 metadata forms rather than allowing uploads or permission changes to silently misbehave.

Changes:

  • Add validation errors with migration guidance for legacy file and permission fields.
  • Add offline tests for rejected metadata and accepted v3 forms.
  • Document date-field replacements and validation behavior in the upgrade guide.
File Description
pydrive2/​test/​test_files_unit.py Tests legacy-field rejection and valid v3 metadata handling.
pydrive2/​files.py Adds v2 metadata checks to uploads and permission creation.
docs/​upgrading.rst Explains field replacements and migration errors.

Review effort: Balanced

Comment thread pydrive2/files.py Resolved
- Upload() and InsertPermission() validate before authentication starts.
- Upload() checks every key of the file, so a metadata read can no longer
  hide a pending v2 field.
- parents must be a list of ID strings; a bare object, a bare ID and None
  are rejected with the same message.
- A tuple of v2 properties is rejected like a list.
- The hints for value, indexableText and thumbnail show the full v3 form.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants